package com.score.util;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtils {

    public static String getHeadPinYin(String str) {
        StringBuilder sb = new StringBuilder();
        char[] chars = str.toCharArray();
        for (Character character :
                chars) {
            String[] strings = PinyinHelper.toHanyuPinyinStringArray(character);
            //获取每个字的拼音，第一个字符转化为大写
            String string = strings[0].substring(0,1).toLowerCase();
            sb.append(string);
        }
        return sb.toString();
    }

    public static String getStringAndInt(String str) {
        StringBuilder sb = new StringBuilder();
        char[] chars = str.toCharArray();
        for (Character character :
                chars) {
            if (Character.isDigit(character)){
                sb.append(character);
            }else{
                String[] strings = PinyinHelper.toHanyuPinyinStringArray(character);
                //获取每个字的拼音，第一个字符转化为大写
                String string = strings[0].substring(0,1).toLowerCase();
                sb.append(string);
            }
        }
        return sb.toString();
    }

}
